import Vue from 'vue'
import App from './App.vue'

//语音朗读
import Speech from 'speak-tts'
//路由
import router from './router'

//保存密码-加密
import CryptoJS from "crypto-js";


//自适应手机端布局
import 'amfe-flexible'

//公共样式表
import '@/assets/css/public.less'

import tab from '@/components/tab.vue'
Vue.component('tab',tab);
import goback from '@/components/goback.vue'
Vue.component('goback',goback);
import copyright from '@/components/copyright.vue'
Vue.component('copyright',copyright);
import showtitle from '@/components/showtitle.vue'
Vue.component('showtitle',showtitle);
import VCode from '@/components/VCode.vue'
Vue.component('VCode',VCode);


import puzzle from '@/components/puzzle.vue'
Vue.component('puzzle',puzzle);

//数据可视化，图表插件
import * as echarts from "echarts";
//百度地图插件
import BaiduMap from 'vue-baidu-map'

Vue.use(BaiduMap, {
  // ak 是在百度地图开发者平台申请的密钥 详见 http://lbsyun.baidu.com/apiconsole/key */
  ak: '百度地图密钥'
})
//访问后端，axios插件
import axios from 'axios';
Vue.prototype.axios = axios;
//录音插件
import Recoder from 'recorder-js';

//Swiper
import VueAwesomeSwiper from 'vue-awesome-swiper'
import 'swiper/css/swiper.css'
Vue.use(VueAwesomeSwiper)



//Dialog
import Message from './components/Message/index';
Vue.use(Message);

// loading
import loading from '@/components/loading.vue';
Vue.component('loading',loading);

// Toast
import Toast from '@/components/Toast.vue'
const ToastPlugin={
	install(Vue){
		Vue.prototype.$toast=new Vue(Toast).$mount();
		document.body.appendChild(Vue.prototype.$toast.$el);
	}
};
Vue.use(ToastPlugin);
Vue.component('Toast',Toast);


import MyEmojis from '@/components/MyEmojis.vue';
Vue.component('MyEmojis',MyEmojis);


const imagesContext = require.context('@/assets/', false, /\.(png|jpe?g|svg)$/);
Vue.prototype.images = imagesContext.keys().map(key => imagesContext(key));

Vue.config.productionTip = false



import recoderModal from '@/components/recoderModal.vue'
Vue.component('recoderModal',recoderModal);


//自动到页面顶部
router.beforeEach((to, from, next) => {  
  window.scrollTo(0, 0); // 滚动到页面顶部
  next(); // 确保一定要调用 next()  
}); 

import store from './store';



//localStorage
Vue.prototype.setStorage = function(key, value,expire=0) {  
  const expirationTime = expire * 60 * 1000;  
  const expirationTimestamp = new Date().getTime() + expirationTime;
  localStorage.setItem(key, JSON.stringify({  
    value: value,  
    expiration: expirationTimestamp
  }));  
};  
Vue.prototype.getStorage = function(key) {  
  const itemStr = localStorage.getItem(key);  
  if (!itemStr) {  
    return null; // 数据不存在  
  }  
  const item = JSON.parse(itemStr);  
  const now = new Date().getTime();  
  if (item.expiration != 0 && now <= item.expiration) {  
    // 数据已过期，从localStorage中删除  
    localStorage.removeItem(key);  
    return null;  
  }  
  return item.value; // 返回未过期的数据值  
};  
Vue.prototype.removeStorage = function(key) {  
  const itemStr = localStorage.getItem(key);  
  if (itemStr) {
   localStorage.removeItem(key);  
  }
  return "";
};  


//IP
Vue.prototype.IP = 'https://lryh.cc:39888'
Vue.prototype.WebSocketIP = 'lryh.cc:39888'
// Vue.prototype.IP = 'https://localhost:39888'
// Vue.prototype.WebSocketIP = 'localhost:39888'
new Vue({
    router,
	store,
    render: h => h(App)
}).$mount('#app')

